#!/usr/bin/env python
import sys
import Image
import json

result = ""
cover = Image.open("input/badcat.png")
imdata = cover.getdata()
data= sys.stdin.read().split("\n")
datalen = len(data)
counter = 0
realcounter=1
for line in data:
    line = line.strip()
    pair = line.split("\t")
    try:
        if counter == 0:
            index = int(pair[1])
        else:
            index = int(pair[1])
            index+=2
            
    except IndexError:
        break
    
    byte = ord(chr(int(pair[0])))

    pixels = [value & ~1 for value in
                  imdata[counter][:3] + imdata[counter+1][:3] + imdata[counter+2][:3]]
    for j in xrange(7, -1, -1):
        pixels[j] |= byte & 1
        byte >>= 1
    if realcounter == datalen-1:
        #print pixels
        pixels[-1] |= 1
    counter+=3
    realcounter+=1
    pixels = tuple(pixels)
    print json.dumps((pixels[0:3],pixels[3:6],pixels[6:9]))
